package cn.wang.web.cargo;


import cn.wang.entity.cargo.Invoice;
import cn.wang.service.cargo.InvoiceService;
import cn.wang.utils.Pagination;
import cn.wang.web.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * extCproductAction
 * Created by john on 2017/11/1.
 */
@Controller
public class InvoiceAction extends BaseAction implements ModelDriven<Invoice> {
    private Pagination page = new Pagination();
    private List<Invoice> InvoiceList;
    private Invoice model = new Invoice();
    //获取id
    private String[] id;

    @Autowired
    private InvoiceService invoiceService;

   //分页展示发票
    public String list() {
        page = invoiceService.findPage(page.getPageNo(), page.getPageSize());
        page.setUrl("invoiceAction_list");
        push(page);
        return "list";
    }


    //查看单个发票
    public String toview() {
        model = invoiceService.findById(model.getId());
        push(model);
        return "toview";
    }

    //新增发票
    public String insert() {
        invoiceService.save(model);
        return "insert";

    }

    //修改发票
    public String toupdate() {
        //根据id查询老shuju1
        model = invoiceService.findById(model.getId());
        push(model);
        return "toupdate";
    }



    //删除发票
    public String delete() {
        if (model.getId() == null) {
            return "rlist";
        }
        String[] ids = model.getId().split(", ");
        invoiceService.delete(ids);
        return "rlist";
    }

    //提交 修改状态
    public String submit() {
        String[] ids = model.getId().split(", ");

        return "rlist";
    }

    public String cancel(){

        return "rlist";
    }
    public void setPage(Pagination page) {
        this.page = page;
    }

    public List<Invoice> getInvoiceList() {
        return InvoiceList;
    }

    @Override
    public Invoice getModel() {
        //将字段名设为model使一行代码两用 1模型驱动 2 字段set方法
        return model;
    }

    public void setId(String[] id) {
        this.id = id;
    }

}
